/**
 * author yueshuai
 * 2017.5.2
 * 对象排序 需要传入对象 和 排序的属性
 * 现在只是支持三级
 */
function compare(propertyName) {
	return function(object1, object2) {
		var value1 = object1[propertyName];
		var value2 = object2[propertyName];
		if (value2 < value1) {
			return 1;
		} else if (value2 >value1) {
			return -1;
		} else {
			return 0;
		}
	}
}

export const objectCompare = function(data,attr) {
	for(var i = 0; i<data.length; i++){
		data.sort(compare(attr));
		if(data[i].children != undefined && data[i].children.length>0){
			data[i].children.sort(compare(attr))
			for(var j= 0; j<data[i].children.length; j++){
				if(data[i].children[j].children != undefined && data[i].children[j].children.length>0){
					data[i].children[j].children.sort(compare(attr))
				}
			}
		}
	}
	return data
}